<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>万恶的Blogbus客户端程序示例</title>
<link type="text/css" href="jqueryUI/jquery.wysiwyg.css" rel="stylesheet" />
<link type="text/css" href="jqueryUI/themes/base/ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="jqueryUI/jquery-1.3.2.js"></script>
<script type="text/javascript" src="jqueryUI/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="jqueryUI/ui/jquery-ui-1.7.2.custom.js"></script>
<script type="text/javascript" src="AIRAliases.js"></script>

<style type="text/css">
/*globe settings*/
* {
	padding: 0;
	margin: 0;
}

body {
	width: 100%;
	height: 100%
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 14px;
	color: #333333;
	/*background:#666;*/
}
img {border: none;}
.clear { clear: both;}

/*Login Form */
#loginForm {
	width: 	400px;
	height: 100px;
	padding: 5px 10px;
	margin-left: -205px;
	position: absolute;
	top: 0px;
	left: 50%;
	z-index: 99;
	background: #999999;
	/*display: none;*/
}
#loginForm div {
	width: 100%;
	float: left;
	margin: 5px 0;
}
#loginForm label {
	width: 70px;
	float: left;
}

div#loginProcess {
	width: 400px;
	position: absolute;
	top: 40px;
	z-index: 100;
	text-align: center;
	display: none;
}
div#loginFailed { display: none;}
/*Post Form */
#postForm {
	position: absolute;
	left: 0;
	top: 25px;
	width: 562px;
	height: 460px;
	padding: 5px 10px;
	float: left;
	opacity: 0.4;
	background: #cccccc;
	/*display: none;*/
}
#postForm #postProcess {
	display: none;
}
#postForm div {
	float: left;
	/*width: 100%;*/
	margin: 5px 0;
}
#postForm label {
	float: left;
	width: 90px;
}
#postForm input {
	width: 250px;
}
#postForm textarea {
	width: 550px;
	height: 250px;
}
iframe {
	border: none;	
}
#postForm div div {margin: 0;}

/*上传文件*/
#filesUpload {
	width: 820px;
	height: 460px;
	overflow: scroll;
	padding: 5px 10px;
	position: absolute;
	top: 25px;
	left: 0px;
	background: #ccc;
	display: none;
}
#foldersLists {
	width: 100%;
	list-style: none;
}
#foldersLists li {
	width: 100px;
	float: left;
	margin: 5px 7px;
}
/*上传区域*/
.uploadDIV {
	display: none;
	width: 680px;
	height: 325px;
	overflow: auto;
	position: absolute;
	top: 70px;
	left: 50%;
	margin-left: -340px;
	background: red;
}

.uploadHeader {
	padding: 5px 0px;
	text-align:right;
}

.uploadProgress {
	width: 200px;
	height: 20px;
}

.ui-progressbar-value {
	background-image: url( images/pbar-ani.gif );
	text-align: center;
}


/*日志列表*/
#entries{
	width: 820px;
	height: 460px;
	overflow: scroll;
	padding: 5px 10px;
	position: absolute;
	top: 25px;
	left: 0px;
	background: #ccc;
	display: none;
}
#readingEntries {
	position: absolute;
	top: 0px;
	left: 0;
	text-align: center;
}

/*文件管理*/
#filesManage {
	width: 260px;
	height: 470px;
	position: absolute;
	top: 25px;
	right: 0px;
	overflow: scroll;
	background: #cccccc;
	/*display: none;*/
}

#filesLists {}
#filesLists li { 
	width: 110px;
	height: 160px;
	overflow: hidden;
	float: left;
}

#pager,.pagecent,.pager {
	margin: 10px 0px;
	display: block;
	clear: both;
}

/*评论管理界面*/
#comments {
	width: 820px;
	height: 460px;
	overflow: scroll;
	padding: 5px 10px;
	position: absolute;
	top: 25px;
	left: 0px;
	background: #ccc;
	display: none;
}
#loadinComments {}
#cmtsLists {
	list-style: none;
	width: 100%;
}
#cmtsLists li {
	width: 100%;
	float: left;
	clear: both;
	margin: 15px 0;
}
.cmtLeft { 
	width: 75px;
	float: left;
}

.cmtRight {
	width: 575px;
	float: right;
}
#cmtsLists h2 {
	font-size: 14px;
}

.replyForm {display: none;}
</style>
</head>

<body ondragenter="preventDefault(event)" ondragover="preventDefault(event)">

<script language="javascript" type="text/javascript">  
function preventDefault(event){  
	event.preventDefault();  
}  
</script>
<!--<div id="info"></div>-->
<!--<div id="progressbar"></div>-->

<!--页面导航链接-->
<div id="header">
<a href="" title="写日志" id="writeEntry">写日志</a>   |   <a href="#" title="日志列表" id="listEntires">日志列表</a>    |    <a href="http://file.home.blogbus.com/" id="uploadIt" title="上传文件">上传文件</a>    |    <a href="#" id="cmtsManage">评论管理</a>    |    <input type="checkbox" id="isAutoLogin" name="isAutoLogin" />取消自动登录
</div>
<!--登录框-->
<form id="loginForm" style="position: absolute;">
	<div id="loginProcess"><img src="images/indicator_arrows.gif" /><br />正在登录，请稍候...</div>
    <div id="loginFailed">登录失败，请检查你的网络状况，或者重新输入用户名和密码。</div>
	<div><label for="userName">用户名：</label><input type="text" id="userName" name="userName" value="" /></div>
    <div><label for="userName">密&nbsp;&nbsp;&nbsp;码：</label><input type="password" id="password"  name="password" value="" /></div>
    <div>
    <input type="submit" id="login" value="登  录" />
        <input type="checkbox" id="isRemembered" name="isRemembered" />记住我
    </div>
</form>

<!--日志标题，发表日期，分类，tag，日志全文-->
<form id="postForm"> 
    <div><label for="userName">日志标题：</label><input type="text" value="请填写日志标题..." id="postTitle" disabled="disabled" /></div>
    <div><label for="userName">发表日期：</label><input type="text" value="" id="postDate" disabled="disabled" /></div>
    <div><label for="userName">日志内容：</label><textarea id="postContent" disabled="disabled" style="display:none;"></textarea>
		<!--<iframe src="tinymce.html" id="postContentFrame" sandboxRoot="http://localhost/air/" documentRoot="app:/jqueryUI/tinymce" scrolling="no" width="550" height="290"></iframe>-->
		<iframe src="simple_editor.html" id="postContentFrame" sandboxRoot="http://air/" documentRoot="app:/jqueryUI/yuiEditor/" scrolling="no" width="570" height="350"></iframe>
    </div>
    <div><input type="submit" id="postEntry" value="发表日志" disabled="disabled" /></div>
    <div id="postProcess"><img src="images/indicator_arrows.gif" />正在发表日志，请稍候...</div>  
    <br class="clear" />
</form>

<!--文件管理界面-->
<div id="filesManage">
<select id="foldersSelection"><option value="正在读取文件夹列表...">正在读取文件夹列表...</option></select>
<ul id="filesLists"></ul>
</div>

<!--文件上传界面-->
<div id="filesUpload">
	<div id="readingFolders"><img src="images/indicator_arrows.gif" />正在读取文件夹列表，请稍候...</div>
    <ul id="foldersLists"></ul>
</div>

<!--日志列表界面-->
<div id="entries">
	<div id="readingEntries"><img src="images/indicator_arrows.gif" />正在读取日志列表，请稍候...</div>
    <div id="entriesLists"></div>
</div>

<!--评论管理界面-->
<div id="comments">
    <div id="loadinComments"><img src="images/indicator_arrows.gif" />正在读取留言，请稍候...</div>
    <ul id="cmtsLists"></ul>
</div>

<script type="text/javascript">
	// 初始化
	var modules = new Array("postForm","filesManage","filesUpload","entries","comments");
	var isLoadingEntries=false,isLoadingFiles=false,isLoadingFolders=false,isLoadingComments=false;
	$("#postDate").val( getDateTime() ); // 设置发表时间为当前时间
	//自动登录
 	try {
		var loginInfoFile = new air.File("F:\\AIR\\loginInfo.dat");
		var stream = new air.FileStream();	
		stream.open(loginInfoFile,air.FileMode.READ);	
		var loginInfo = stream.readObject();
		stream.close();
		if (loginInfo.user!=null && loginInfo.password != null) {
			$("#userName").val(loginInfo.user);
			$("#password").val(loginInfo.password);
			loginIn(loginInfo.user,loginInfo.password);
		}	
	} catch(e) {
		stream.close();	
		//alert("打开文件失败或者其它原因");
	}
	$("#userName").focus();
	$("#postTitle").focus( function(){
						  		if( $(this).val() == "请填写日志标题..." )  $(this).val("");
						  });
	
	
	/* 事件监听列表
	**监听登录表单的提交事件*/
	$("#loginForm").submit( function() { loginIn();	return false; });
	
	
	/**监听发表日志表单的提交事件*/
	$("#postForm").bind("submit", function() { postBlog(); return false;  });
	
	/**取消自动登录的click事件*/
	$("#isAutoLogin").click( function(){ 
										if( confirm('您真的要取消自动登录吗？')) {
											//alert('取消成功！');
											var loginInfo = new Object();
											loginInfo.user = null;
											loginInfo.password = null;
											var file = new air.File("F:\\AIR\\loginInfo.dat");
											var stream = new air.FileStream();
											stream.open(file,air.FileMode.UPDATE);
											stream.writeObject(loginInfo);
											stream.close();														
											$(this).attr("disabled","disabled");
										 } else { return false; }
									});
	
	/**为writeEntry链接绑定click事件*/
	$("#writeEntry").click( function(){ 
										 showModule( modules, new Array("postForm","filesManage") );
										 $("#postTitle").val("");
										 $("#postDate").val( getDateTime() );
										 filesManager();
										 /**监听发表日志表单的提交事件*/									 
										 $("#postForm").unbind("submit").bind("submit", function() { postBlog(); return false;  });
										 return false;
									});
	
	/**为listEntries链接绑定click事件*/
	$("#listEntires").click( function() {
										  //alert("hi,jiee");
										  showModule( modules, new Array("entries") );								  
										  getEntries("?mm=Post");
										  return false;
									  });
	
	
	/**为upload链接绑定click事件*/
	$("#uploadIt").click(function() {
								  	showModule( modules, new Array("filesUpload") );
									getFolders();
									return false;
								});
	
	/**为cmtsManage绑定click事件*/
	$("#cmtsManage").click( function() {
										showModule( modules, new Array("comments") );
										cmtsManager();
										return false;
									 });
	
	/*事件响应函数列表*/
	/**登录并设置isLoggedIn*/
	function loginIn(u,p) {
		var user = u ? u : $("#userName").val();
		var password =p ? p : $("#password").val();
		var isUserRemembered = $("#isRemembered").attr("checked");
		//alert(user +" " + password);
		
		$("#loginForm div:visible").fadeTo("fast",0.4);
		$("#loginForm input").attr("disabled","disabled");
		$("#loginProcess").show();
		
		var url = new air.URLRequest("http://www.blogbus.com/user/login.php");
		var loader = new air.URLLoader();	
		url.method =  air.URLRequestMethod.POST;
		url.data = "username=" + user + "&password=" + password;
		loader.addEventListener(air.IOErrorEvent.IO_ERROR, function() {
														   //$("#loginForm").toggle("bounce",{"times": 2,"distance":150},400);
														   $("#loginProcess").hide();
														   $("#loginFailed").dialog('destroy').dialog({'title':'登陆失败！','position':'top','modal':'true'});
														   $("#loginForm div:visible").fadeTo("fast",1);
														   $("#loginForm input").removeAttr("disabled");	
														});
		loader.addEventListener(air.Event.COMPLETE, function() {
															pattern = /id="logpage"/g; // 登录页面特有的id
															if (pattern.test(loader.data)) { //登录失败
																isLoggedIn = false;
																$("#loginProcess").hide();
																$("#loginForm div:visible").fadeTo("fast",1);
																$("#loginForm input").removeAttr("disabled");
																$("#loginFailed").dialog('destroy').dialog({'title':'登陆失败！','position':'top','modal':'true'});
															} else { // 登录成功
																isLoggedIn = true;
																$("#loginForm").toggle("bounce",{"times": 2,"distance":150},400);
																$("#postForm").fadeTo("fast",1);
																$("#postForm input").removeAttr("disabled");
																if (isUserRemembered) {
																	var loginInfo = new Object();
																	loginInfo.user = user;
																	loginInfo.password = password;
																	var file = new air.File("F:\\AIR\\loginInfo.dat");
																	var stream = new air.FileStream();
																	stream.open(file,air.FileMode.UPDATE);
																	stream.writeObject(loginInfo);
																	stream.close();
																} 
																filesManager();
																//getEntries("?mm=Post");
																//getFolders();
																//filesManager();
																//blogId = getBlogId();
																//getFiles(blogId);
																//cmtsManager();
																//replyComment()
															}															
														});
		loader.load( url );	
	}
	
	function getFolders() { // 取得文件夹和文件列表
		$("#readingFolders").show();
		$("#foldersLists").empty();
		var url = new air.URLRequest("http://file.home.blogbus.com/");
		var loader = new air.URLLoader();
		airReferer = new air.URLRequestHeader("Referer","http://www.blogbus.com/user/");
		url.requestHeaders = new Array(airReferer);
		loader.addEventListener(air.Event.COMPLETE, function() { // 解析页面，获得文件夹图标和文件夹链接
															 //alert( loader.data );
															 $("#foldersLists").empty();
															 $("#readingFolders").hide();
															 pattern = /<div.*?icon.*href="(.*?)".*src="(.*?)"[\s\S]*?title="(.*?)"/g;
															 pattern2 = /<div.*?icon.*href="(.*?)".*src="(.*?)"[\s\S]*?title="(.*?)"/;
															 var s = loader.data.match(pattern);
															 folderLists = "";
															 for ( var i=0;i<s.length;i++ ) {
																folderLists +=  '<li><a id="folder_'+i+'" href="http://file.home.blogbus.com'+s[i].match(pattern2)[1]+'"><img src="' + s[i].match(pattern2)[2] + '" /></a><span>' + s[i].match(pattern2)[3] + '</span></li>';
															 }
															 $("#foldersLists").append(folderLists);
															 $("#foldersLists a").bind("click", function() {
																									   var tID = $(this).attr("id"); //e.g:folder_0
																									   var uploadURL = $(this).attr("href").replace(/(thumbs|items)/,"upload");
																									   dropTimes = 0;
																									   //alert( uploadURL );																							   
																									   $("#foldersLists a").each( function(i) {
																																		 //alert( "folder_"+i == tID );
																																		 if("folder_"+i != tID) 
																																		 	$("#upload_folder_"+i).hide();
																																		 });
																									   
																									   if( $("#upload_"+tID).length == 0 ) {
																									   		$(this).after("<div class='uploadDIV' id='upload_"+tID+"'><div class='uploadHeader'><button class='selectFileButton'>请选择文件</button>  |  <a href='#'>关闭X</a></div></div>");
																									   }
																									   $("#upload_"+tID).toggle("drop",{"direction": "up"},400);
																									   $("#upload_"+tID+" a").one("click", function() { 
																																		//alert("hi,hi,jiee");
																																		$(this).parent().parent().toggle("drop",{"direction": "up"},400);
																																	});
																									   $(".selectFileButton").bind("click",function() {
																																						var file = new air.File();
																																						file.addEventListener( air.FileListEvent.SELECT_MULTIPLE, function(event) {	
																																																						   		dropTimes++;
																																																						   		uploadFiles( uploadURL, event.files, "upload_"+tID+"_"+dropTimes );
																																																						   });
																																						file.browseForOpenMultiple("请选择您需要上传的文件...");
																																					});
																									   
																									   
																									   
																									   document.getElementById( "upload_"+tID ).addEventListener( "drop", function() {
																																												   //alert( event.target.id );
																																												   dropTimes++;
																																												   var filelist = event.dataTransfer.getData(event.dataTransfer.types[0]);
																																												   filesToUpload = new Array();
																																												   for ( var prop in filelist ) {
																																													   //alert(filelist[prop].url);
																																													   var urlStr = filelist[prop].url;
																																													   var file = new air.File(urlStr);
																																													   //alert(file.size);
																																													   filesToUpload.push(file);
																																													}
																																													//alert( uploadURL );
																																													uploadFiles( uploadURL, filesToUpload, event.target.id+"_"+dropTimes );
																																												   });
																									   return false;																							   
																									   });															 
															});
		loader.load( url );
	}
	
	function uploadFiles( uploadURL, filesToUpload, uploadFolderID ) {
		alert( uploadURL +"  "+filesToUpload.length + "   " + uploadFolderID.replace(/(_\d+)$/g,""))
		
		var url = new air.URLRequest(uploadURL);
		url.method =  air.URLRequestMethod.POST;
		
		for ( var f in filesToUpload ) { 
			//创建进度条
			$("#"+uploadFolderID.replace(/(_\d+)$/g,"")).append("<div class='uploadProgress' id='"+uploadFolderID+"progress_" + f + "'></div>");
			uploadIt(filesToUpload[f],"#"+uploadFolderID+"progress_" + f);
		}
		function uploadIt(file,progressID) {
			$(progressID).progressbar();
			
			file.addEventListener(air.ProgressEvent.PROGRESS,function(event) {
																				  var percent = Math.round(event.bytesLoaded/event.bytesTotal * 100);
																				  $(progressID).progressbar('option', 'value', percent );
																				  if ( percent != 100 ) {																				  	
																				  	$(progressID+" .ui-progressbar-value").html( percent + "%" );
																				  } else {
																				  	$(progressID+" .ui-progressbar-value").html( "正在等待系统处理...." );	
																				  }
																				  });
			file.addEventListener(air.Event.COMPLETE, function(event) { alert(event.target.name+" has finished!");$(progressID).remove(); });
			file.upload(url);
		}
	}
	
	function filesManager() {
		$("#filesManage").show();
		var url = new air.URLRequest("http://file.home.blogbus.com/");
		var loader = new air.URLLoader();
		airReferer = new air.URLRequestHeader("Referer","http://www.blogbus.com/user/");
		url.requestHeaders = new Array(airReferer);
		loader.addEventListener(air.Event.COMPLETE, function() { 
															 //alert( loader.data );
															 pattern = /class="info"[\s\S]*?href="(.*?)".*title="([\s\S]*?)"/g;
															 pattern2 = /class="info"[\s\S]*?href="(.*?)".*title="([\s\S]*?)"/;
															 var s = loader.data.match(pattern);
															 var defaultFolder = s[0].match(pattern2)[1];															 
															 //alert( s.length + "    " +  defaultFolder );
															 
															 var lists = "";
															 for ( var i in s ) {
															 	lists += "<option value='" + s[i].match(pattern2)[1] + "'>" + s[i].match(pattern2)[2] + "</option>";
															 }
															 //alert( lists );
															 $("#foldersSelection").empty().append( lists ).change( function() {
																													 	//alert( " hi,hi ");
																													 	//alert( $("#foldersSelection option:selected").val() );
																														var folderID = $("#foldersSelection option:selected").val();
																														getFiles(folderID);
																													 });
															 
															 
															 getFiles(defaultFolder);
															 });
		loader.load( url );		
	}
	
	function getFiles(folder) {
		if(isLoadingFiles) return;
		isLoadingFiles = true;
		$("#filesLists").empty();
		//$("#filesLists").append ("<iframe src='http://file.home.blogbus.com/documents/2046077/thumbs'></ifame>");
		var url = new air.URLRequest("http://file.home.blogbus.com" + folder.replace("items","thumbs"));
		var loader = new air.URLLoader();
		airReferer = new air.URLRequestHeader("Referer","http://www.blogbus.com/user/");
		url.requestHeaders = new Array(airReferer);
		loader.addEventListener(air.Event.COMPLETE, function() { 
															 	var pager = loader.data.match(/<span\sclass='pager'>(.*)<\/span>/g);
															 	
															 	//alert(loader.data);
															 	pattern = /class="icon".*href="(.*?)".*?="([\s\S]*?)".*<img.src="(.*)"[\s\S]*?value="(\d+)"/g;
																pattern2 = /class="icon".*href="(.*?)".*?="([\s\S]*?)".*<img.src="(.*)"[\s\S]*?value="(\d+)"/;
															 	var s = loader.data.match(pattern);
																//alert(s);
																var lists = "";
																for ( var i in s ) {
																	lists += "<li><a class='fileIcon' href='"+s[i].match(pattern2)[1]+"'><img src='"+s[i].match(pattern2)[3].replace("http://filer","http://www.hongkongfans.cn/filer")+"' /></a><p>"+s[i].match(pattern2)[2]+"</p></li>"	
																}
																//alert(lists);
																																
																$("#filesLists").append( lists ).append( pager[0].replace("class='pager'","id='pager'") );
																//alert( $("#filesLists").html() );
																$(".fileIcon").bind("click",function() {
																									 	var href = $(this).attr("href");
																										var title = $(this).next().html();
																									 	//alert( $(this).children("img").attr("src") );
																										if( /(jpg|gif|png|bmp)/i.test(href) ) {
																											insertIMG(href.replace("http://filer","http://www.hongkongfans.cn/filer"));
																										} else {
																											insertLink("<a href='"+href+"' title='"+title+"'>"+title+"</a>")
																										}
																										return false;
																									 });
																$("#pager a").bind("click",function() {
																										folder = $(this).attr("href");
																										//alert( folder );
																										getFiles(folder);
																										return false;
																									});
																isLoadingFiles = false;				   
															 });
		loader.load(url);
		//filesLists;
	}
		
	function postBlog(para) { // 发表日志函数
		$("#postEntry").hide();
		$("#postProcess").show();	
		var blogTitle = $("#postTitle").val().replace(/\s/g,"+"); //replace blank by + 
		var postTime = $("#postDate").val();
		var blogContent = getHTML();
		
		if ( !para ) {
			var url = new air.URLRequest("http://www.blogbus.com/user/?mm=Post&aa=SaveAdd&page=&outputmode=1");	
			url.data = "Title="+blogTitle+"&PostTime="+postTime+"&SortID=0&tContent="+blogContent+"&Tags=&Excerpt=&Trackback=&ID=&DraftId=0&force=0";
		} else {
			var url = new air.URLRequest("http://www.blogbus.com/user/?mm=Post&aa=SaveEdit&page=&outputmode=1");
			url.data = "Title="+blogTitle+"&PostTime="+postTime+"&SortID=0&tContent="+blogContent+"&Tags=&Excerpt=&Trackback=&ID="+para.match(/id=(\d+)$/i)[1]+"&DraftId=0&force=0";
			//alert(url.data);
			//return;
		}		
		var loader = new air.URLLoader();
		url.method =  air.URLRequestMethod.POST;
		
		url.requestHeaders = new Array(new air.URLRequestHeader("Referer","http://www.blogbus.com/"));
		
		loader.addEventListener(air.Event.COMPLETE, function() { 
															 //alert(loader.data);
															 if ( loader.data.indexOf("提交成功") != -1 ) {
																//发表成功 , 转到日志管理界面
																getEntries("?mm=Post");
																showModule( modules, new Array("entries") );
																$("#postEntry").show();
																$("#postProcess").hide();
															  } else {
																//发表失败 
																alert("对不起，遇到错误，您可以试着重新登录后发表日志");
																$("#postEntry").show();
																$("#postProcess").hide();
															  }
														});
		loader.load(url);
	}
	
	function getEntries(page) {
		//$("#entries").show().load("http://www.blogbus.com/user/?mm=Post #pub_main table");
		if(isLoadingEntries) return;
		isLoadingEntries = true;		
		$("#readingEntries").show();
		$("#entriesLists").empty();
		var url = new air.URLRequest("http://www.blogbus.com/user/"+ page);
		var loader = new air.URLLoader();
		airReferer = new air.URLRequestHeader("Referer","http://www.blogbus.com/user/");
		url.requestHeaders = new Array(airReferer);
		loader.addEventListener(air.Event.COMPLETE, function() { // 解析页面，获得各链接信息
															 $("#readingEntries").hide();
															 var pager = loader.data.match(/<div\sclass="pagecent".*<\/div>/);
															 //alert( pager );
															 
															 pattern = /<td.*aid="(\d+)"[\s\S]*?tdCenter">(.*?)<\/td>[\s\S]*?href="(.*?)">(.*?)<\/a>[\s\S]*?href="(.*?)"[\s\S]*?href="(.*?)">(.*?)<\/a>[\s\S]*?href="(.*?)">[\s\S]*?href="(.*?)">(\d+)<\/a>/g;
															 pattern2 = /<td.*aid="(\d+)"[\s\S]*?tdCenter">(.*?)<\/td>[\s\S]*?href="(.*?)">(.*?)<\/a>[\s\S]*?href="(.*?)"[\s\S]*?href="(.*?)">(.*?)<\/a>[\s\S]*?href="(.*?)">[\s\S]*?href="(.*?)">(\d+)<\/a>/;
															 //alert( loader.data.match(pattern).length );
															 var entriesLists = '<table cellpadding="0" cellspacing="0"><tbody>'+
																	 ' 		<tr> '+
																	 '			<th>标题</th> '+
																	 '			<th style="width:110px;">分类</th> '+
																	 '			<th style="width:100px;" class="tdCenter">日期</th> '+
																	 '			<th style="width:40px;" class="tdCenter">评论</th> '+
																	 '		</tr> ';
																	 
															 s = loader.data.match(pattern);
															 for ( var i in s ) {
															 	//$("#entries").append( "aid="  + s[i].match(pattern2)[1] + "<br />Date=" + s[i].match(pattern2)[2] + "<br />editID=" + s[i].match(pattern2)[3]+ "<br />title=" + s[i].match(pattern2)[4] + "<br />" );
																entriesLists += 
																	'<tr>'+
																	'	<td><a class="entries" href="http://www.blogbus.com/user/'+s[i].match(pattern2)[3]+'">'+s[i].match(pattern2)[4]+'</a><a href="'+s[i].match(pattern2)[5]+'"><img src="images/popup.gif" /></a></td>'+
																	'	<td><a href="http://www.blogbus.com/user/'+s[i].match(pattern2)[6]+'">'+s[i].match(pattern2)[7]+'</a></td>'+
																	'	<td>'+s[i].match(pattern2)[2]+'</td>'+
																	'	<td><a href="'+s[i].match(pattern2)[9]+'">'+s[i].match(pattern2)[10]+'</a></td>'+
																	'</tr>'												
															 }
															 //alert(entriesLists+"</table>");
															 entriesLists += "</tbody></table>";
															 $("#entriesLists").append(entriesLists).append( pager[0] );
															 $(".pagecent a").bind("click", function() {
																									   getEntries( $(this).attr("href") );
																									   return false;
																								   });
															 $(".entries").bind("click", function() {
																										modifyEntry( $(this).attr("href") );
																										return false;
																									});
															 isLoadingEntries = false;
															 });
		loader.load(url);
	}
	
	function modifyEntry(entryID) {
		$("#readingEntries").show(); //显示加载层
		var pattern= /name="Title".value="([\s\S]*?)".*value="(.*?)"[\s\S]*?<textarea.*?>([\s\S]*?)<\/textarea>/;
		var url = new air.URLRequest(entryID);
		var loader = new air.URLLoader();
		loader.addEventListener(air.Event.COMPLETE, function() {
															 	$("#readingEntries").hide(); //隐藏加载层
															 	var s = loader.data.match( pattern );
															 	//alert( s );
																showModule( modules, new Array("postForm","filesManage") );
																$("#postTitle").val( s[1] );
																$("#postDate").val( s[2] );
																$("#postContent").html( s[3] );
																document.getElementById("postContentFrame").contentWindow.childSandboxBridge.setHTML($("#postContent").html());
																$("#postForm").unbind().bind("submit", function() { postBlog(entryID); return false;  });
															});
		loader.load( url );
	}
	
	function cmtsManager(page) {
		if(isLoadingComments) return;
		isLoadingComments = true;		
		$("#loadinComments").show();
		$("#cmtsLists").empty();
		if ( !page ) 	{ 
			var url = new air.URLRequest("http://blog.home.blogbus.com/comments/items"); 
			//alert( "hi,jiee" );
		} else {
			var url = new air.URLRequest("http://blog.home.blogbus.com"+ page);
		}
		var loader = new air.URLLoader();
		loader.addEventListener(air.Event.COMPLETE, function() {
															 	$("#loadinComments").hide();
															 	var pager = loader.data.match(/<span\sclass='pager'>(.*)<\/span>/g);
															 	var pattern = /id="(comment_\d+)".*>[\s\S]*?src="(.*)"[\s\S]*?blank">([\s\S]*?)<\/a>.*cmt_time">.*<span[\s\S]*?<h6>(.*)<\/h6>[\s\S]*?class="cmt_full".*>[\s\S]*?<p>([\s\S]*?)<\/p>[\s\S]*?<form.*>([\s\S]*?)<\/form>[\s\S]*?id="reply_info_\d+">([\s\S]*?)<\/div>/g;
															 	var pattern2 = /id="(comment_\d+)".*>[\s\S]*?src="(.*)"[\s\S]*?blank">([\s\S]*?)<\/a>.*cmt_time">.*<span[\s\S]*?<h6>(.*)<\/h6>[\s\S]*?class="cmt_full".*>[\s\S]*?<p>([\s\S]*?)<\/p>[\s\S]*?<form.*>([\s\S]*?)<\/form>[\s\S]*?id="reply_info_\d+">([\s\S]*?)<\/div>/;
																var s = loader.data.match( pattern );
																var lists = "";
																for ( var i in s ) {
																	var n = s[i].match( pattern2 );
																	lists += "<li>" +
																				"<div class='cmtLeft'>" +
																					"<img src='" + n[2] +"' />" +
																					"<div>" + n[4] + "</div>" +
																				"</div>" + 
																				"<div class='cmtRight'>" +
																					"<h2>" + n[3] + "</h2>" +
																					"<p class='cmtContent'>" + n[5] + "</p>" +
																					"<p class='replyContent' id='"+ n[1] +"_re'>" + n[7] + "</p>"+
																					"<form class='replyForm' id='"+n[1]+"_reForm'>" + n[6] + "</form>" + "<a class='replyComment' href='#"+n[1]+"'>回复留言</a> | <a class='delComment' href='#" + n[1] +"'>X</a>" +
																				"</div>" + 
																			"</li>";																	
																}
																//alert( lists );
																$("#cmtsLists").append ( lists ).append ( pager[0] );
																$("#cmtsLists .pager a").bind("click",function() {
																											   		cmtsManager( $(this).attr("href") );
																													return false;
																											   });
																$(".replyComment").click(function(){
																										var formID = $(this).attr("href") + "_reForm";
																										var replyContentID = $(this).attr("href") + "_re";
																										$(replyContentID).toggle("blind");
																										$(formID).toggle("blind");
																										return false;
																									});
																$(".replyForm").submit( function() {
																								 	//alert(this.blogid.value);
																									replyComment(this.blogid.value,this.rid.value,this.cmid.value,this.reply.value);																																					  
																									return false;																																				  
																								 });
																$(".replyForm :button").click(function() {  
																									   $(this).parent().prev().toggle("blind");
																									   $(this).parent().toggle("blind"); 																									   
																									   return false;
																								 });
																
																$(".delComment").click(function(){ 
																									// del cmid todo
																									return false;
																								});
																isLoadingComments = false;
																																
															 });
		loader.load( url );
	}
	
	function replyComment(blogID,replyID,cmtID,replyContent) {
		var url = new air.URLRequest("http://blog.home.blogbus.com/"+blogID+"/comments/reply"); //http://blog.home.blogbus.com/4486206/comments/reply	
		var loader = new air.URLLoader( url );
		url.method =  air.URLRequestMethod.POST;
		url.data = "blogid="+blogID+"&cmid="+cmtID+"&content="+replyContent+"&rid="+replyID;		
		//alert(url.data);
		url.requestHeaders = new Array(new air.URLRequestHeader("Referer","http://blog.home.blogbus.com/comments/items"),new air.URLRequestHeader("Accept","text/json"));
		loader.addEventListener( air.Event.COMPLETE, function() {
															  	alert( loader.data );
																if ( /"success"/.test(loader.data) ) {
																		var pattern = /{"today":"(.*?)","rid":(\d+)}/;
																		var s = loader.data.match(pattern);
																		
																		$("#comment_"+cmtID+"_reForm input[name='rid']").attr("value",s[2]);
																		$("#comment_"+cmtID+"_reForm").toggle("blind");
																		$("#comment_"+cmtID+"_re").html("我回复道："+replyContent).show();
																		//alert( $("#comment_"+cmtID+"_reForm input[name='rid']").attr("value") );
																	}
															  });
		loader.load( url );
	}
	
	/*功能函数*/	
	function showModule(modules,modulesShown) {		
		for ( var i=0; i<modules.length; i++) {
			$("#" + modules[i]).hide();
		}
		
		for ( var i=0; i<modulesShown.length; i++ ) {
			$("#" + modulesShown[i]).show();
		}
	}
	
    function getHTML() {
      return document.getElementById("postContentFrame").contentWindow.childSandboxBridge.getHTML();
    }
	function setHTML(val) {
		document.getElementById("postContentFrame").contentWindow.childSandboxBridge.setHTML(val);
	}
	function insertIMG(src) {
		document.getElementById("postContentFrame").contentWindow.childSandboxBridge.insertIMG(src);
	}
	function insertLink(val) {
		document.getElementById("postContentFrame").contentWindow.childSandboxBridge.insertLink(val);
	}
	function getDateTime(){
		var d = new Date();
		var y = d.getFullYear();
		var mon = parseInt(d.getMonth()) + 1;
		var da = d.getDate();
		var h = d.getHours();
		var m = d.getMinutes();
		var s = d.getSeconds();
		return y+"-"+mon+"-"+da+" "+h+":"+m+":"+s;
	}

</script>
</body>
</html>
